export function isSubtree(
  root: TreeNode | null,
  subRoot: TreeNode | null
): boolean {
  if (!root || !subRoot) return false;
  const isSameTree = (node1: TreeNode | null, node2: TreeNode | null) => {
    if (!node1 && !node2) return true;
    if (!node1 || !node2) return false;
    if (node1.val !== node2.val) return false;
    return (
      isSameTree(node1.left, node2.left) && isSameTree(node1.right, node2.right)
    );
  };
  const res = isSameTree(root, subRoot);

  return res || isSubtree(root.left, subRoot) || isSubtree(root.right, subRoot);
}
